<?php

namespace app\crm\model\contract;

use think\Model;



class Contract extends Model
{
       // 表名
       protected $name = 'crm_contract';
       // 自动写入时间戳字段
       protected $autoWriteTimestamp = 'int';
       // 定义时间戳字段名
       protected $createTime = 'create_time';
       protected $updateTime = 'update_time';
       protected $deleteTime = 'delete_time';
       public function setOrdertimeAttr($value)
       {
              return strtotime($value);
       }
       public function setStarttimeAttr($value)
       {
              return strtotime($value);
       }
       public function setEndtimeAttr($value)
       {
              return strtotime($value);
       }
       public function getEndtimeAttr($value)
       {
              return date("Y-m-d ", $value);
       }
       public function getOrdertimeAttr($value)
       {
              return date("Y-m-d ", $value);
       }
       public function getStarttimeAttr($value)
       {
              return date("Y-m-d ", $value);
       }
       public function getStatusAttr($value)
       {
              $status = [0 => '交易中', 1 => '交易成功', 2 => '回款成功'];
              return $status[$value];
       }
       public static function info()
       {
              return db('crm_client')->field('id,name')->select();
       }
       public static function business()
       {
              return db('crm_business')->field('id,name')->select();
       }
       public static function salesman()
       {
              return db('yd_crm_admin')->field('id,account')->select();
       }
           /**
     * @Descripttion: 客户
     * @Date: 2022-11-30 15:23:36
     */    

    public function ourclients()
    {

        return $this->belongsTo('app\crm\model\client\Ourclients','client_id','id');
    }
    /**
     * @Descripttion: 创建人
     * @Date: 2022-12-10 09:41:33
     */    
    public function sale()
    {
        return $this->hasOne('app\crm\model\auth\Admin','id','sale_id');
        
    }
    /**
     * @Descripttion: 负责人
     * @Date: 2022-12-10 19:05:44
     */    
    public function principal()    
    {
        return $this->belongsTo('app\crm\model\auth\Admin','principal_id','id');
        
    } 
    /**
     * @Descripttion: 订单产品关系
     * @Date: 2022-12-10 19:05:51
     */    
    public function product()
    {
       return $this->hasMany('app\crm\model\contract\Product','contract_id','id');
        
    }
    /**
     * @Descripttion: 商机
     * @Date: 2022-12-10 19:06:22
     */    
    public function cllist()
    {
       return $this->hasOne('app\crm\model\commercial\Cllist','id','business_id');
        
    }

}
